<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <main id="app">
        <ul>
            <li v-for="item in tableData" :key="item.t_content_pk" @click="selectedItem = item">{{item.title}}</li>
        </ul>
        <h3>详情展示</h3>
        <content-detail :item="selectedItem"></content-detail>
    </main>
</body>
<script src="./static/vue3.js"></script>
<script src="./static/axios.min.js"></script>
<script>
    const { createApp } = Vue;

    const app = createApp({
        components: {
            "content-detail": {
                template: `<div v-html="rowData.content"></div>`,
                data() {
                    return {
                        rowData: {}
                    }
                },
                props: {
                    item: {
                        type: Object,
                        required: true,
                    }
                },
                watch: {
                    item: {
                        handler(newVal) {
                            axios({
                                baseURL: "https://www.forerunnercollege.com/soApi",
                                url: "/content/queryRow",
                                method: "post",
                                data: { "t_content_pk": newVal.t_content_pk }
                            }).then(res => {
                                if (res.data.status > 0) {
                                    this.rowData = res.data.result_data;
                                }
                            })
                        }
                    }
                }
            }
        },
        data() {
            return {
                tableData: [],
                selectedItem: {},
            }
        },
        // 生命周期钩子函数
        created() {
            axios({
                baseURL: "https://www.forerunnercollege.com/soApi",
                url: "/content/queryList",
                method: "post",
                data: { "t_cat_plant_fk": "405", "rows": "5" }
            }).then(res => {
                if (res.data.status > 0) {
                    this.tableData = res.data.result_data;
                }
            })
        }
    });

    app.mount("#app");
</script>

</html>